<template>
	<view class="index-content">
		<TopBar :indexflag="true" :combakflag="true" :lang="false" :bottom="true" :title="$t('Order')" barstyle="#45bc1b" Color="#fff"></TopBar>
		<view class="order-list">
			<scroll-view scroll-y="true" style="height:100%;width:100%" @scrolltolower="scrolldata">
				<!-- 我的订单 -->
				<u-empty v-if="orderList.length==0" style="padding-top: 200rpx;" mode="order" iconSize="100"
					textSize="14" :text="$t('OrderEmpty')">
				</u-empty>
				<view class="list" v-if="orderList.length" :dir="i18nLocale=='ug'?'rtl':''"
					v-for="(item,index) in orderList" @click="handdetail(item.id)">
					<!-- <view class="">{{item.order.out_trade_no}}</view> -->
					<view class="time">
						<text>{{$t('TimePlaced')}}:</text>
						{{item.order?item.order.paid_at:''}}
						<u-icon name="checkmark-circle-fill" color="#45bc1b" size="25" ></u-icon>
					</view>
					<view class="order-item">
						<view class="item" v-for="(subitem,sub_index) in item.content">
							<view class="left">
								<!-- <view class="index">{{sub_index+1}}.</view> -->
								<image :src="getImgSrc(subitem.img)" mode=""></image>
								<view class="name">{{i18nLocale=='ug'?subitem.ug_name:subitem.cn_name}}</view>
							</view>
							<view class="right">
								<view class="number">X{{subitem.qty}}</view>
								<view class="price">￥{{subitem.price}}</view>
							</view>
						</view>
						<view class="totalprice-box">
							<text>{{$t('TotalPrice')}}</text>
							<text class="totalprice">￥{{item.fee}}</text>
						</view>
					</view>
				</view>
				<Loading :show="tabloadshow" :text="$t('Loading')" style="width:100%;height:100%;position: absolute;">
				</Loading>
			</scroll-view>
			<Loading :show="loadshow" bgColor="" iconName="circle" :text="$t('Loading')"></Loading>
		</view>
	</view>
</template>

<script>
	import TopBar from "@/components/TopBar.vue"
	import HeaderTitle from "@/components/HeaderTitle.vue"
	import {
		getorder,
		orderstatus
	} from '@/api/all.js';

	export default {
		components: {
			TopBar,
			HeaderTitle,
		},
		mounted() {
			this.scrolldata();
		},
		data() {
			return {
				orderList: [],
				pageSize: 5,
				page: 1,
				total: 0,
				to: 1,
				tabloadshow: false,
				loadshow: false,

			}
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
		},
		methods: {
			scrolldata() {
				if (this.to != this.total) {
					this.loadshow = true;
					this.getOrders();
				} else {

				}
			},


			getOrders() {
				let that = this;
				getorder({
					per_page: that.pageSize,
					page: that.page,
					status: 1
				}).then((res) => {
					if (res.code == 200) {
						let data = res.body;
						that.total = data.total;
						that.to = data.to;
						that.page++;
						let mydata = that.orderList.concat(data.data);
						that.orderList = mydata;
						that.tabloadshow = false;
						that.loadshow = false;
					}
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.index-content {
		width: 100%;
		height: 100vh;
		box-sizing: border-box;

		.topnav {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-around;
			background-color: $uni-bg-color-box;
			box-sizing: border-box;
			padding: 20rpx 20rpx;
			font-size: $uni-font-size-base;

			.acitem {
				color: $uni-color-topic;
			}
		}

		.order-list {
			width: 100%;
			height: calc(100% - 170rpx);
			box-sizing: border-box;
			padding: 0rpx 20rpx;

			.list {
				width: 100%;
				background: #FFFFFF;
				box-shadow: $uni-bg-shadow;
				border-radius: $uni-border-radius-lg;
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx 40rpx;
				box-sizing: border-box;

				.time {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					color: #000;

					text {
						color: #808080;
					}

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.order-item {
					width: 100%;
					display: flex;
					flex-direction: column;

					.item {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 20rpx 0rpx;

						.left {
							display: flex;
							align-items: center;

							image {
								width: 120rpx;
								height: 120rpx;
								border-radius: 20rpx;
							}

							.name {
								color: $uni-color-title;
								font-size: $uni-font-size-base;
								padding: 0rpx 30rpx;
							}
						}

						.right {
							display: flex;
							align-items: center;

							.price {
								color: $uni-color-topic;
								font-size: $uni-font-size-base;
								padding: 0rpx 30rpx;
							}

							.number {
								color: $uni-text-color-grey;
								font-size: $uni-font-size-sm1;
								padding: 0rpx 30rpx;
							}

						}

					}

					.totalprice-box {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.totalprice {
							color: #f4464b;
							font-size: 45rpx;
						}
					}

					.button {
						background-color: $uni-color-topic;
						border-radius: $uni-border-radius-lg;
						padding: 20rpx 80rpx;
						margin: 0 auto;
						color: #fff;
					}


				}
			}
		}
	}
</style>